package model;

import com.vandorenmes.argus.R;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

/**
 */
public class CaptureHandler extends Handler {
    public static final String DECODED_DATA = "decoded_data";
    private Context context;
    private OnDecodedCallback callback;

    public CaptureHandler(Context context, OnDecodedCallback callback) {
        this.context = context;
        this.callback = callback;
    }

    @Override
    public void handleMessage(Message msg) {
    	String data = msg.getData().getString(DECODED_DATA);
        switch (msg.what) {
            case R.id.decoded:
                if (callback != null){
                    callback.onDecoded(data);
                }
                break;
                
            case R.id.decode_failed:
                CameraManager.getInstance().requestNextFrame(new PreviewCallback(this, context));
                break;
                
            case R.id.WCFresponse_failed:
            	Log.e("wcf", "failed");
            	callback.onWcfResponse(data);
            	break;
            	
            case R.id.WCFresponse_received:
            	callback.onWcfResponse("");	
            	break;
            	
            case R.id.loading:
            	callback.onLoading();
            	break;
        }
    }

    public static interface OnDecodedCallback {
        void onDecoded(String decodedData);
        void onLoading();
        void onWcfResponse(String decodedData);
    }
}
